package com.example.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.ygc_user;
import com.example.mapper.ygcUserMapper;
import com.example.service.ygcUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class IygcUserServiceImpl extends ServiceImpl<ygcUserMapper,ygc_user> implements ygcUserService {
    @Autowired
    ygcUserMapper ygcUserMapper;

    @Override
    public ygc_user queryById(int id) {
        return ygcUserMapper.selectById(id);
    }

    @Override
    public IPage<ygc_user> queryByPage(int pageNo, int pageSize) {
        IPage<ygc_user> pageEmp=new Page<ygc_user>(pageNo,pageSize);
        return ygcUserMapper.selectPage(pageEmp,null);
    }

    @Override
    public List<ygc_user> queryWrapper() {
        QueryWrapper<ygc_user> queryWrapper= new QueryWrapper<>();
        QueryWrapper<ygc_user> queryWrapper1 = queryWrapper.eq("age", 18).ge("version", "1").like("emp_name","Jack");

        return ygcUserMapper.selectList(queryWrapper1);
    }

    @Override
    public List<ygc_user> filter() {
        List<ygc_user> list = ygcUserMapper.selectList(null);
        List<ygc_user> a = list.stream().filter(s -> s.getName().startsWith("Jack")).collect(Collectors.toList());
        return a;

    }

    @Override
    public List<ygc_user> limit() {
        List<ygc_user> list = ygcUserMapper.selectList(null);
        List<ygc_user> collect = list.stream().limit(3).collect(Collectors.toList());
        return collect;
    }
}
